{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('', '')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1 = ''\n",
    "str2,str3 = str1.replace('有效期:','').split('至') if str1 else ('','')\n",
    "str2,str3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'20'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1 = \"20元优惠券\"\n",
    "import re\n",
    "m = re.search(r'\\d+',str1)\n",
    "m.group() if m else ''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "local ip:192.168.10.42 \n",
      "external IP:DESKTOP-V6DQT6T\n",
      "external IP:[]\n",
      "external IP:['192.168.10.42']\n"
     ]
    }
   ],
   "source": [
    "import socket\n",
    "localIP = socket.gethostbyname(socket.gethostname())#得到本地ip\n",
    "print \"local ip:%s \"%localIP\n",
    " \n",
    "ipList = socket.gethostbyname_ex(socket.gethostname())\n",
    "for i in ipList:\n",
    "    if i != localIP:\n",
    "       print \"external IP:%s\"%i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "不存在\n"
     ]
    }
   ],
   "source": [
    "print u'\\u4e0d\\u5b58\\u5728'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "title:描述相符,score:4.7 ,name:描述相符,highGap:13.25;title:服务态度,score:4.8 ,name:服务态度,highGap:14.29;title:发货速度,score:4.7 ,name:物流服务,highGap:8.10\n"
     ]
    }
   ],
   "source": [
    "list1 = [{\"highGap\": \"13.25\", \"score\": \"4.7 \", \"name\": \"描述相符\", \"title\": \"描述相符\"}, {\"highGap\": \"14.29\", \"score\": \"4.8 \", \"name\": \"服务态度\", \"title\": \"服务态度\"}, {\"highGap\": \"8.10\", \"score\": \"4.7 \", \"name\": \"物流服务\", \"title\": \"发货速度\"}]\n",
    "ss = ''\n",
    "ss = ';'.join([','.join([k+':'+v for k,v in item.items()]) for item in list1])\n",
    "print ss\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'FormatError' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-6-de11105f6e17>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mFormatError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\" not db return ! \"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'FormatError' is not defined"
     ]
    }
   ],
   "source": [
    "raise FormatError(\" not db return ! \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cookie2=9653be24f5afed4afed98d8d34aee07b; _tb_token_=Ynix2Qa1q3Yq; t=22b8b413f6cad2f8a03257faf3685b0d; v=0; cookie32=c8a5f163d5c439e7ddfa16873dc7de17; cookie31=MTIwMzk2Njc3LGxjZjA3MCU0MGFsaW1hbWEsNjg4MzQwOTE2QGFsaW1hbWEuY29tLFRC; alimamapwag=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV09XNjQpIEFwcGxlV2ViS2l0LzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZS80OS4wLjI2MjMuMTEwIFNhZmFyaS81MzcuMzY%3D; login=VFC%2FuZ9ayeYq2g%3D%3D; alimamapw=WAVXAgBVEgBTUF5bDFBZWGtWAQIFBFZSAAQBBAULU1JSCQFVA1UCUAZSBlJXAFZXAw%3D%3D; tlut=UoW%2BuvgNaRJ%2B5Q%3D%3D; account-path-guide-s1=true; rurl=aHR0cDovL3B1Yi5hbGltYW1hLmNvbS8%2Fc3BtPWEyMzIwLjczODg3ODEuYTIxNHRyOC4xNS4wamlVSVk%3D; l=AmBg3v3V2qRvyhn93pwEH-UYsGQyaUQz; isg=AmZmzQ_MAgX3Jtah2c29Wzcpt9wNWqoBrdGKmFAPUglk0wbtuNf6EUwhXXgl; cna=xBRaEao5SxACATs5z4KHP0Eh; apushe7fcfa8c1f7bfe42edc160e4a9365b2e=%7B%22ts%22%3A1492409442123%2C%22heir%22%3A1492409308691%2C%22parentId%22%3A1492409241295%7D'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1 = \"cookie2=9653be24f5afed4afed98d8d34aee07b; _tb_token_=Ynix2Qa1q3Yq; t=22b8b413f6cad2f8a03257faf3685b0d; v=0; cookie32=c8a5f163d5c439e7ddfa16873dc7de17; cookie31=MTIwMzk2Njc3LGxjZjA3MCU0MGFsaW1hbWEsNjg4MzQwOTE2QGFsaW1hbWEuY29tLFRC; alimamapwag=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV09XNjQpIEFwcGxlV2ViS2l0LzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZS80OS4wLjI2MjMuMTEwIFNhZmFyaS81MzcuMzY%3D; login=VFC%2FuZ9ayeYq2g%3D%3D; alimamapw=WAVXAgBVEgBTUF5bDFBZWGtWAQIFBFZSAAQBBAULU1JSCQFVA1UCUAZSBlJXAFZXAw%3D%3D; tlut=UoW%2BuvgNaRJ%2B5Q%3D%3D; account-path-guide-s1=true; rurl=aHR0cDovL3B1Yi5hbGltYW1hLmNvbS8%2Fc3BtPWEyMzIwLjczODg3ODEuYTIxNHRyOC4xNS4wamlVSVk%3D; l=AmBg3v3V2qRvyhn93pwEH-UYsGQyaUQz; isg=AmZmzQ_MAgX3Jtah2c29Wzcpt9wNWqoBrdGKmFAPUglk0wbtuNf6EUwhXXgl; cna=xBRaEao5SxACATs5z4KHP0Eh; apushe7fcfa8c1f7bfe42edc160e4a9365b2e=%7B%22ts%22%3A1492409442123%2C%22heir%22%3A1492409308691%2C%22parentId%22%3A1492409241295%7D\"\n",
    "str1"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "collapsed": true
   },
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-4-953a2fc71d3f>, line 12)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-4-953a2fc71d3f>\"\u001b[1;36m, line \u001b[1;32m12\u001b[0m\n\u001b[1;33m    from = 'alimama',\u001b[0m\n\u001b[1;37m       ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "d = dict(TPL_username = 'xmyandayu',\n",
    "TPL_password = '',\n",
    "ncoSig = '',\n",
    "ncoSessionid = '',\n",
    "ncoToken = 'affe870fbf2a7bd8127d5b2b3887e64a1bb0256f',\n",
    "slideCodeShow = 'false',\n",
    "useMobile = 'false',\n",
    "lang = 'zh_CN',\n",
    "loginsite = '0',\n",
    "newlogin = '0',\n",
    "TPL_redirect_url = 'http://login.taobao.com/member/taobaoke/login.htm?is_login=1',\n",
    "from = 'alimama',\n",
    "fc = 'default',\n",
    "style = 'mini',\n",
    "css_style = '',\n",
    "keyLogin = 'false',\n",
    "qrLogin = 'true',\n",
    "newMini = 'false',\n",
    "newMini2 = 'true',\n",
    "tid = '',\n",
    "loginType = '3',\n",
    "minititle = '',\n",
    "minipara = '',\n",
    "pstrong = '',\n",
    "sign = '',\n",
    "need_sign = '',\n",
    "isIgnore = '',\n",
    "full_redirect = 'true',\n",
    "sub_jump = '',\n",
    "popid = '',\n",
    "callback = '',\n",
    "guf = '',\n",
    "not_duplite_str = '',\n",
    "need_user_id = '',\n",
    "poy = '',\n",
    "gvfdcname = '10',\n",
    "gvfdcre = '687474703A2F2F7075622E616C696D616D612E636F6D2F3F73706D3D61323332302E373338383738312E613231347472382E31352E334C4C455766',\n",
    "from_encoding = '',\n",
    "sub = '',\n",
    "TPL_password_2 = '8931ae668cd8eb9040dc400637a7ff3a415a177d60dd445d2309d58deb0818fce2f3d2629743ae68968b2836618b7e4ad4bb3f36d49796b5b0b7d68c22632cf8c4f488429120871d0f8605f673016dcdd960ec068e667905225c1abc07d77145190da9495db4d7bb28d93d70e37bc753b9aa0ebf7648379ee00439dde2ea6a50',\n",
    "loginASR = '1',\n",
    "loginASRSuc = '1',\n",
    "allp = '',\n",
    "oslanguage = 'zh-CN',\n",
    "sr = '1366*768',\n",
    "osVer = '',\n",
    "naviVer = 'firefox|52',\n",
    "osACN = 'Mozilla',\n",
    "osAV = '5.0 (Windows)',\n",
    "osPF = 'Win32',\n",
    "miserHardInfo = '',\n",
    "appkey = '',\n",
    "nickLoginLink = '',\n",
    "mobileLoginLink = 'https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&from=alimama&redirectURL=http://login.taobao.com/member/taobaoke/login.htm?is_login=1&full_redirect=true&disableQuickLogin=true&useMobile=true',\n",
    "showAssistantLink = '',\n",
    "ua = '090#qCQXN4XtXEYXITi0XXXXXQk63ofYTUGGfwVoOFhiyECEWrYCcI+xbQ8YOgFnlURnztJoK+eLG013z5Q4hI5tZ282Irp9biYiXi+VeGPuKOM3o7e/rTx045qoD/sJLgq+l5sNDx4iXiw47V7MIWQ7PzwAAFKD2VPasL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267MIB39PzwAAvduaLOFW0luAvfOXvXSO/23coNAraQ1U0D2BTtrubZsiGDQqTQXi6W21d5OXvXSOimMcoN1sjQ1U0D2BTtrubZsiGDQHXQXuzreceVyVBlkpf58s8vW4TUy4Wg8iioviJDRXvXg7pY8iJN3oVMhH1DuuJPGvySN0lKrj4==',\n",
    "um_token = 'HV01PAAZ0ab8131e7824e38b58f58153009f4a46')\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'http://i.taobao.com/my_taobao.htm?nekot=eG15YW5kYXl11492500129882\"'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import re\n",
    "str1 = 'top.location.href = \"http://i.taobao.com/my_taobao.htm?nekot=eG15YW5kYXl11492500129882\"'\n",
    "m = re.search(r'http://i.taobao.com/my_taobao.htm\\?nekot=.*?\"',str1,re.S)\n",
    "m.group()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2017-04-18'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "time.strftime(\"%Y-%m-%d\",time.localtime(int(1492563749)-1*24*3600))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'149256457068'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(time.time()).replace('.','')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2017, tm_mon=4, tm_mday=19, tm_hour=9, tm_min=2, tm_sec=29, tm_wday=2, tm_yday=109, tm_isdst=0)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime(1492563749)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'http://pub.alimama.com/report/getTbkPaymentDetails.json?startTime=2017-01-20&endTime=2017-04-19&payStatus=&queryType=1&toPage=1&perPageSize=20&total=&t=149267600588&pvid=&_tb_token_=1234&_input_charset=utf-8'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import re\n",
    "str1 = 'http://pub.alimama.com/report/getTbkPaymentDetails.json?startTime=2017-01-20&endTime=2017-04-19&payStatus=&queryType=1&toPage=1&perPageSize=20&total=&t=149267600588&pvid=&_tb_token_=&_input_charset=utf-8'\n",
    "str2 = re.sub(r'_tb_token_=.*?&','_tb_token_=1234&',str1)\n",
    "str2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'_tb_token_': 'HfxG3Y2KKeYq',\n",
       " 'alimamapw': 'TAtIU1kBVk0WOAIHBQUCWFVRBAQEBQ5XVFJTUgEFUgJWCFVXUlIAVlIH',\n",
       " 'alimamapwag': 'TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV09XNjQpIEFwcGxlV2ViS2l0LzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZS80OS4wLjI2MjMuMTEwIFNhZmFyaS81MzcuMzY%3D',\n",
       " 'cna': 'uWR/EUgZLVACAd5PTeus9V/b',\n",
       " 'cookie2': 'f26ffd535770f4fa2a8fd0bf11fc690e',\n",
       " 'cookie31': 'MTEyMDIxMjc2LHhteWFuZGF5dSx5ZHlAZG9mYXN0LmNvbS5jbixUQg%3D%3D',\n",
       " 'cookie32': 'fbba75510e5034ab1db0451021f395b1',\n",
       " 'login': 'URm48syIIVrSKA%3D%3D',\n",
       " 't': 'e3f2dca75ca9199e00216ac8f06f0de4',\n",
       " 'v': '0'}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1 = 'cna=uWR/EUgZLVACAd5PTeus9V/b;cookie31=MTEyMDIxMjc2LHhteWFuZGF5dSx5ZHlAZG9mYXN0LmNvbS5jbixUQg%3D%3D;cookie2=f26ffd535770f4fa2a8fd0bf11fc690e;t=e3f2dca75ca9199e00216ac8f06f0de4;_tb_token_=HfxG3Y2KKeYq;v=0;login=URm48syIIVrSKA%3D%3D;cookie32=fbba75510e5034ab1db0451021f395b1;alimamapw=TAtIU1kBVk0WOAIHBQUCWFVRBAQEBQ5XVFJTUgEFUgJWCFVXUlIAVlIH;alimamapwag=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV09XNjQpIEFwcGxlV2ViS2l0LzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZS80OS4wLjI2MjMuMTEwIFNhZmFyaS81MzcuMzY%3D'\n",
    "\n",
    "str2 = dict([s.split('=') for s in str1.split(';')])\n",
    "str2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import subprocess\n",
    "cmd = 'del 2017log.txt'\n",
    "P = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)\n",
    "P.wait()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "401"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "r = requests.get('https://api.github.com/user', auth=('user', 'pass'))\n",
    "r.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'123': [], 'response': []}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "HOOKS = ['response','123']\n",
    "dict((event, []) for event in HOOKS)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import urllib2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
